Content:
The data used in this project is of animal sightings on the trail cameras around the Duke forest and the spatial data of the Duke forest;it was collected as part of an ongoing project monitoring the white-tail deer population.
The data used in this project is of animal sightings on the trail cameras around the Duke forest and the spatial data of the Duke forest;it was collected as part of an ongoing project monitoring the white-tail deer population.
To conduct a deer survey with trail cameras, one camera must be placed every 160 or so acres. (Source: Thomas Jr., L. (2012, April 19). How to run a trail-camera survey. Quality Deer Management Association.) The Duke forest is 7,000 acres.(Source: Duke University. (n.d.). Duke Forest – Teaching and Research Laboratory. Retrieved from https://dukeforest.duke.edu) There are 30 trail cameras in the Duke forest along known migration paths.
library(here)
here() #get working directory
## [1] "/Users/sophiemoyer/Documents/EDE-Final"
knitr::include_graphics(here("Images", "buck_day.jpg"))
#import packages
library(tidyverse)
library(lubridate)
library(viridis)
library(rvest);
library(dataRetrieval)
library(dplyr)
library(readr)
library(stringr)
library(sf);
library(mapview); mapviewOptions(fgb = FALSE)
library(RColorBrewer)
#install.packages("AICcmodavg")
library(AICcmodavg)
##install.packages("multcompView")
library(multcompView)
##install.packages("ggstatsplot")
library(ggstatsplot)
#install.packages("kableExtra")
#library(kableExtra)
custom.theme <- function() {
theme_minimal() +
theme(
panel.background = element_rect(fill = "seashell"),
panel.grid.major = element_line(colour = "bisque2", linetype = "dashed"),
axis.line = element_line(colour = "black", size = 0.5),
axis.text = element_text(size = 10, color = "salmon3", angle = 10),
axis.title = element_text(size = 12, face = "bold", color = "salmon4"),
plot.title = element_text(size = 16, color = "black", face = "bold", hjust = 0.5),
plot.subtitle = element_text(size = 12, color = "gray", hjust = 0.5),
legend.text = element_text(size = 10, color = "salmon3"),
legend.title = element_text(size = 12, color = "salmon4", face = "bold"),
legend.position = "right"
)
}
#read excel file
trailcam_csv <- read.csv(here("Data", "Raw", "sequences.csv"))
moon_phases_csv <- read.csv(here("Data", "Raw", "moon_phases.csv"))
#date as objects
trailcam_csv$start_time <- ymd_hms(trailcam_csv$start_time)
trailcam_csv$end_time <- ymd_hms(trailcam_csv$end_time)
moon_phases_csv$start_date <- as.Date(moon_phases_csv$start_date)
#separate date and time
trailcam_csv$start_date <- as.Date(trailcam_csv$start_time)
trailcam_csv$start_time <- format(trailcam_csv$start_time, "%H")
trailcam_csv$month <- month(as.Date(trailcam_csv$start_date))
trailcam_csv$month_name <- month.name[trailcam_csv$month]
trailcam_csv$end_date <- as.Date(trailcam_csv$end_time)
trailcam_csv$end_time <- format(trailcam_csv$end_time, "%H")
#filter for white- tailed deer, select relevant columns, and isolate trail camera id number.
deer_data <- trailcam_csv %>%
filter(common_name == "White-tailed Deer") %>%
select(common_name, deployment_id, start_date, start_time, group_size, month, month_name) %>%
mutate(cam_id = as.numeric(str_extract(deployment_id, "\\d+")),
division = str_extract(deployment_id, "\\((.*?)\\)"))
#cam_id refers to the camera id number
#mutate(cam_id = as.numeric(str_extract(deployment_id, "\\d+"))) taken from stackoverflow
#read file with trail camera coordinates (delivered as a .xlsx and converted to a .csv)
cam_coords <- read.csv(here("Data", "Raw", "camera_coords.csv"))
#Select id number and coordinates
cam_coordinates <- cam_coords %>%
mutate(cam_id = as.numeric(str_extract(deployment_id, "\\d+")))
#join deer data with trail camera coordinate data to find where cameras are, and clean up data
deer_cam_data <- left_join(deer_data, cam_coordinates, by = "cam_id") %>%
select(common_name, start_date, start_time, group_size, cam_id, division, longitude, latitude, month, month_name)
deer_cam_data <- left_join(deer_cam_data, moon_phases_csv, by = "start_date")
#categorize hours into groups
deer_cam_data$start_time <- as.numeric(deer_cam_data$start_time)
categorize_time <- function(hour) {
ifelse(hour >= 6 & hour < 12, "Morning",
ifelse(hour >= 12 & hour < 20, "Afternoon", "Evening"))
}
deer_cam_data$time_category <- cut(deer_cam_data$start_time,
breaks = c(-Inf, 5.99, 11.99, 19.99, Inf),
labels = c("Evening", "Morning", "Afternoon", "Evening"),
right = FALSE)
categorize_moon_phase <- function(phase) {
phase_lower <- tolower(phase)
if (grepl("full", phase_lower) || grepl("gibbous", phase_lower)) {
return("FullAndGibbous")
} else if (grepl("new", phase_lower) || grepl("crescent", phase_lower)) {
return("NewAndCrescent")
} else {
return("QuarterMoon")
}
}
deer_cam_data$moon_type <- sapply(deer_cam_data$moon_phase, categorize_moon_phase)
#read Duke forest boundary shapefile into project
#here("Duke University/Documents/EDE_Fall2023/DukeForest-TackRiosMoyer/duke-forest-spatial-data/duke-forest-spatial-data/Boundary")
#forest_sf <- st_read("Duke_Forest_Boundary_Mar2022.shp")
#mapview(forest_sf)
#adding a new column - categorical time of day
deer_data <- deer_data %>% mutate(
TOD = case_when(
start_time %in% c(20, 21, 22, 23, "00", "01", "02", "03") ~ 'night ',
start_time %in% c("04", "05", "06", "07", "08", "09", 10, 11) ~ 'morning',
start_time %in% c(12, 13, 14, 15, 16, 17, 18, 19) ~ 'day',
TRUE ~ NA_character_
)
)
#categorical variable for moon phase
deer_data <- inner_join(deer_data, moon_phases_csv, by = "start_date")
#convert coordinates to a spatial dataframe
#deer_cam_data_sf <- deer_cam_data_sf %>% st_as_sf(coords = c("Longtitude","Latitude"), crs=4326)
deer_data <- deer_data %>%
arrange(month, start_time)
deer_hours <- deer_data %>%
group_by(month, start_time, month_name) %>%
mutate(sightings = 1, .groups = 'drop') %>%
summarise(sightings = sum(sightings), .groups = 'drop')
ggplot(deer_hours, aes(x = start_time, y = sightings, group = month, color = as.factor(month_name))) +
geom_line() +
labs(title = "Deer Sightings", x = "Hour", y = "Sightings") +
scale_color_discrete(name = "Month") + custom.theme() + facet_wrap(~ month_name, ncol = 1)
The graphical representation delineates discernible peaks in deer sightings throughout the day, with particular emphasis on a notable surge in April during both the early morning and evening hours. This graphical depiction aligns with our initial hypothesis, posited as follows: “The time of day has no discernible effect on deer observations.”
h <- hist(deer_data$group_size, main = "Histogram of Deer Observations", xlab = "Group Size", xlim = c(0,7), ylim = c(0,650), col = "tan", border = "brown")
text(h$mids,h$counts,labels=h$counts, adj=c(0.5, -0.5))
The observational data pertaining to deer frequency underscores a prevailing trend wherein a majority of the observed deer exhibited solitary movement. Deer may choose to move solo instead of in a herd for various ecological and behavioral reasons, as supported by scientific literature. One key study conducted by Kjellander and Nordstrom (2003) sheds light on some key factors influencing deer movement patterns, including: Resource Acquisition and Competition, Territorial Behavior and Mating Strategies, Avoidance of Predation and Social Dynamics and Dispersal.
It is important to acknowledge that the observational data utilized in this study pertains specifically to the spring of 2023. This temporal parameter bears significance as it may impact herd size, attributable to one or more of the factors elucidated earlier.
Source: Kjellander, P., & Nordstrom, J. (2003). Cyclic voles, prey switching in red fox, and roe deer dynamics—a test of the alternative prey hypothesis. Oikos, 101(2), 338-344. doi:10.1034/j.1600-0706.2003.12118.x
Methods
In light of the available dataset, our analytical approach involves the application of analysis of variance (ANOVA) tests to assess the implications posited by hypotheses one and three. The underlying premise is to ascertain the absence of any discernible relationship between these variables, signifying an absence of influence from temporal and lunar factors on deer behavior. ANOVA is selected as the preferred statistical method for this investigation due to its efficacy in evaluating relationships between quantitative and categorical variables. In our specific context, group size is treated as a quantitative variable, while time of day (TOD) and moon phase are both considered categorical.
Hypothesis One - The time of day does not have an impact on observed deer
#testing hypothesis one - time of day has no effect on deer observations
time.one.way <- aov(group_size ~ TOD, data = deer_data)
one.way.result <- summary(time.one.way)
timeone <- as.data.frame(one.way.result[[1]])
#timeone %>% kbl(caption = "One-Way ANOVA") %>% kable_paper("hover", full_width = F)
The p-value (Pr(>F)) is less than 0.05, indicating that there is
evidence to reject the null hypothesis. Therefore,
there is a statistically significant difference in means among the
groups defined by TOD. However, the specific interpretation
of which groups are different would require further post-hoc tests or
examination of the group means.
Hypothesis Three - The phase of the moon has no impact on observed deer
#testing hypothesis three - moon phase has no impact on deer observations
moon.one.way <- aov(group_size ~ moon_phase, data = deer_data)
moon.one <- summary(moon.one.way)
moontable <- as.data.frame(moon.one[[1]])
#moontable %>% kbl(caption = "One-Way ANOVA") %>% kable_paper("hover", full_width = F)
The F value of 1.089 is associated with a p-value of 0.368. Since the p-value is greater than the conventional significance level (0.05), we fail to reject the null hypothesis. This suggests that there is no significant difference in the means of the groups based on the moon phases. Based on the results, moon phases do not appear to have a statistically significant effect on the amount of deer observed in the Duke Forest.
Hypothesis Four - The phase of the moon has no effect on the time of day deer are observed
contigency_table <- table(deer_data$start_time, deer_data$moon_phase)
chisq_result <- chisq.test(contigency_table)
print(chisq_result)
##
## Pearson's Chi-squared test
##
## data: contigency_table
## X-squared = 237.95, df = 161, p-value = 7.687e-05
The Chi-Square statistic (237.95) is substantial, indicating a substantial deviation from the expected frequencies based on the assumption of independence between the categorical variables. The extremely small p-value (7.687e-05) suggests strong evidence against the null hypothesis of independence. With a p-value below the conventional significance level (e.g., 0.05), we reject the null hypothesis.
Based on the results, there is sufficient evidence to conclude that there is a significant association between the phase of the moon and the time of day deer are observed. The observed frequencies differ significantly from what would be expected under the assumption of independence.
One-Way ANOVA for Time of Day and Deer Observations
tukey.one.way <- TukeyHSD(time.one.way)
tukeytable <- as.data.frame(tukey.one.way[[1]])
#tukeytable %>% kbl(caption = "Tukey Multiple Comparison of Means") %>% kable_paper("hover", full_width = F)
plot(tukey.one.way, las = 1)
In summary, the Tukey HSD test suggests that the
group_size differs significantly between night and morning,
while there is no significant difference between morning and day or
night and day. Keep in mind that the interpretation of p-values
depends on the chosen significance level (commonly 0.05), and
adjustments may be made for multiple comparisons.
Chi-Squared Model for Moon Phases and Time of Day
ggbarstats(data = deer_data, x = moon_phase, y= TOD, label = "both")
The presented bar plot indicates a discernible influence of moon phase, particularly during the waning gibbous phase, on the temporal patterns of deer sightings. The data collection methodology, wherein the camera recorded instances exclusively when a deer was present, enables us to consider the recorded time (TOD) as indicative of deer sightings. Notably, there is a pronounced surge in deer sightings during daylight hours when the moon is in a waning gibbous phase. While morning and night also exhibit an increase in deer sightings, the magnitude of this increase is comparatively more pronounced during the day.
Interpretations
The outcomes of our statistical analyses yield discernible insights, prompting the rejection of null hypotheses one and four. Null hypothesis one’s rejection signifies a discernible influence of time of day on deer sightings within the Duke Forest. Employing the Tukey Honest Significant Difference (HSD) test revealed a significant disparity in the number of deer observed between nighttime and morning periods. Although the ANOVA tests did not precisely pinpoint the time period with the highest deer sightings, they collectively provide compelling evidence suggesting increased deer activity during the morning and night compared to the day.
The rejection of null hypothesis four implies a notable association between the moon’s phase and the timing of deer observations in the Duke Forest. Specifically, a conspicuous rise in deer sightings during the daytime is evident during the waning gibbous phase. While morning and night also experience heightened deer sightings, the magnitude is comparatively subdued. Additional observations from the plot further highlight noteworthy observations concerning other moon phases — new moon, last quarter, full moon, and first quarter. Each are seemingly associated with some degree of limitation in deer observations. Particularly intriguing is the observation that the new moon phase corresponds to the lowest incidence of deer sightings. This could potentially be attributed to the absence of ambient light, resulting in total darkness and potentially obscuring the vision of the camera traps, unless equipped with night vision capabilities.
In summary, the rejection of null hypotheses one and four underscores the influence of time of day and moon phase on deer observations in the Duke Forest. These findings provide a foundation for deeper explorations into the temporal dynamics of deer behavior, offering valuable insights for wildlife management and conservation considerations.
Limitations
The present study is subject to certain limitations that warrant consideration. Foremost among these limitations is the relatively modest sample size and the narrow time frame within which observations were conducted. The dataset spans a duration of three months, and the restricted number of observations poses challenges in establishing robust relationships. The limited temporal scope of the study may not capture the full spectrum of factors influencing deer behavior during the spring of 2023.
The brevity of the observational period raises concerns regarding the generalizability of findings, particularly in discerning nuanced patterns or relationships. The intricate interplay of various environmental and ecological factors, beyond the parameters of time of day and moon phase, may have influenced deer behavior during the specified period. The absence of an extended temporal context restricts the ability to differentiate between temporal idiosyncrasies specific to the spring of 2023 and broader trends recurring across multiple spring seasons.
Furthermore, the inability to compare the spring of 2023 with analogous seasons over a more protracted timeframe limits the broader applicability of the study’s findings. Without a comprehensive assessment across multiple spring seasons, the outcomes may be confounded by seasonal variations, hindering a conclusive determination of causality. In order to comprehensively elucidate the factors influencing deer behavior, future studies with extended observation periods and larger datasets encompassing diverse temporal contexts are imperative. Addressing these limitations would contribute to a more nuanced and robust understanding of the dynamics underpinning deer behavior in relation to time of day and moon phase.
Future Analysis
The current investigation lays the groundwork for a continuous and collaborative research initiative, closely aligned with the Duke Forest team’s focus on camera trap data. This ongoing study is poised to evolve over time, leveraging the accumulation of additional data to facilitate a more comprehensive and robust statistical analysis. As the dataset expands, the study anticipates an enriched foundation for exploring intricate patterns and relationships within the observed phenomena.
While our primary emphasis rested on the behavior of White-Tail Deer, it is noteworthy that a myriad of other species were documented in the observations. This diversity prompts an avenue for future exploration, suggesting a valuable opportunity to compare and contrast the findings related to White-Tail Deer with those of other species thriving within the Duke Forest ecosystem. Such an interdisciplinary approach could potentially unveil broader ecological insights and contribute to a more holistic understanding of the dynamics governing wildlife interactions. Spatial considerations also beckon attention, inviting an exploration of whether the behavior exhibited by White-Tail Deer in the Duke Forest is congruent with that of their counterparts in the surrounding Durham area.
In summary, the study’s ongoing nature, collaborative framework, and interdisciplinary possibilities underscore its potential for continuous refinement and expansion. The integration of additional data, the exploration of diverse species, and the spatial analysis of deer behavior hold promise for deepening our understanding of wildlife dynamics within and beyond the Duke Forest ecosystem.
#Bringing in Location data
#duke_forest<- st_read("/home/guest/module1/DukeForest-TackRiosMoyer/Data/Raw/Duke_Forest_Boundary_Mar2022.shp")
#converting camera points to locations
cameras.sf <- st_as_sf(cam_coordinates, coords = c("longitude","latitude"),
crs=4326)
#wrangling to include number of deer sightings at each location
Deer_location_data <- deer_cam_data%>%
group_by(cam_id) %>%
summarise(total_deer = sum(group_size))
#join to locations
Deer_location_data <- left_join(cameras.sf,Deer_location_data,by="cam_id")
#set 0 sightings
Deer_location_data$total_deer[is.na(Deer_location_data$total_deer)] <- 0
Deer_location_data_morning <- deer_cam_data%>%
filter(time_category=='Morning') %>%
group_by(cam_id) %>%
summarise(total_deer = sum(group_size))
#join to locations
Deer_location_data_morning <-
left_join(cameras.sf,Deer_location_data_morning,by="cam_id")
#set 0 sightings
Deer_location_data_morning$total_deer[
is.na(Deer_location_data_morning$total_deer)] <- 0
Deer_location_data_afternoon <- deer_cam_data%>%
filter(time_category=='Afternoon') %>%
group_by(cam_id) %>%
summarise(total_deer = sum(group_size))
#join to locations
Deer_location_data_afternoon <-
left_join(cameras.sf,Deer_location_data_afternoon,by="cam_id")
#set 0 sightings
Deer_location_data_afternoon$total_deer[
is.na(Deer_location_data_afternoon$total_deer)] <- 0
Deer_location_data_evening <- deer_cam_data%>%
filter(time_category=='Evening') %>%
group_by(cam_id) %>%
summarise(total_deer = sum(group_size))
#join to locations
Deer_location_data_evening <-
left_join(cameras.sf,Deer_location_data_evening,by="cam_id")
#set 0 sightings
Deer_location_data_evening$total_deer[
is.na(Deer_location_data_evening$total_deer)] <- 0
#Plotting Camera sites and number of dear sighings at each one
mapview(cameras.sf,cex = 4, map.types="OpenStreetMap.Mapnik",
layer.name="Location of Camera Traps")
mapview(Deer_location_data,
cex = 5,
map.types="OpenStreetMap.Mapnik",
col.regions=heat.colors(10,rev=TRUE),
na.color="white",
zcol="total_deer",
layer.name="Number of Deer")
#plotting dear sighings at each camera trap for different times of the day
mapview(Deer_location_data_morning,
cex = 5,
map.types="OpenStreetMap.Mapnik",
col.regions=heat.colors(10,rev=TRUE),
na.color="white",
zcol="total_deer",
layer.name="Number of Deer in the Morning")
mapview(Deer_location_data_afternoon,
cex = 5,
map.types="OpenStreetMap.Mapnik",
col.regions=heat.colors(10,rev=TRUE),
na.color="white",
zcol="total_deer",
layer.name="Number of Deer in the Afternoon")
mapview(Deer_location_data_evening,
cex = 5,
map.types="OpenStreetMap.Mapnik",
col.regions=heat.colors(10,rev=TRUE),
na.color="white",
zcol="total_deer",
layer.name="Number of Deer in the Evening")
#scatter plot of herd size and time of day
scatter.deer.time.herd <-
ggplot(deer_cam_data, aes(x = start_time, y = group_size)) +
geom_point() +
geom_smooth(method = loess, color="black") +
labs(
title = "Herd Size Observed Based on Time of Day",
x = "Time of Day (hour)",
y = "Herd Size"
) +
custom.theme()
print(scatter.deer.time.herd)
#insert image of phases of the moon for reference purposes
knitr::include_graphics(here("Images", "moon_phases.png"))
#scatter plot of herd size and moon phase
scatter.deer.moon.herd <-
ggplot(deer_cam_data, aes(x = moon_phase, y = group_size)) +
geom_point() +
labs(
title = "Herd Size Observed Based on Moon Phase",
x = "Moon Phase",
y = "Group Size"
) +
scale_x_discrete(labels = c("new moon", "waxing crescent", "first quarter", "waxing gibbous", "full moon", "waning gibbous", "third quarter", "waning crescent")) +
scale_y_continuous(breaks = seq(0, ceiling(max(deer_cam_data$group_size)), by = 1)) +
custom.theme()
#scale_x_discrete to get labels in order that I want them to be
print(scatter.deer.moon.herd)
#scatter plot of moon phase and time of day
scatter.deer.moon.time <-
ggplot(deer_cam_data, aes(x = moon_phase, y = start_time)) +
geom_point() +
geom_smooth(method = lm, color="black") +
labs(
title = "Deer Observed Based on Moon Phase & Time of Day",
x = "Moon Phase",
y = "Time of Day (hour)"
) +
custom.theme()
print(scatter.deer.moon.time)
#scatter plot of month and time of day, sorted by herd size
scatter.deer.time.month <-
ggplot(deer_cam_data, aes(x = start_date, y = start_time, color = group_size)) +
geom_point() +
geom_smooth(method = lm, color="black") +
labs(
title = "Deer Observed Based on Month & Time of Day",
subtitle = "Categorized by Herd Size",
x = "Month",
y = "Time of Day (hour)",
color = "Herd Size"
) +
custom.theme()
print(scatter.deer.time.month)
scatter.deer.time.day.moon <-
ggplot(deer_cam_data, aes(x = start_date, y = moon_type, color = time_category)) +
geom_point() +
labs(
title = "Deer Observed Based on Month & Moon Phase",
subtitle = "Categorized by Time of Day",
x = "Month by Date",
y = "Moon Phase (type)",
color = "Time of Day (type)"
) +
custom.theme()
print(scatter.deer.time.day.moon)
deer.moon.time.heatmap <-
ggplot(deer_cam_data, aes(x = moon_phase, y = start_time, fill = group_size)) +
geom_tile() +
scale_fill_gradient(low = "yellow", high = "red") +
labs(
title = "Deer Observed Based on Moon Phase & Time of Day",
subtitle = "Characterized by Herd Size",
x = "Moon Phase",
y = "Time of Day (hour)",
fill = "Herd Size"
) +
custom.theme()
print(deer.moon.time.heatmap)
deer.cam.time.heatmap <-
ggplot(deer_cam_data, aes(x = start_time, y = cam_id, fill = group_size)) +
geom_tile() +
scale_fill_gradient(low = "yellow", high = "red") +
labs(
title = "Deer Observed Based on Time of Day & Camera",
subtitle = "Characterized by Herd Size",
x = "Time of Day (hour)",
y = "Camera ID",
fill = "Herd Size"
) +
scale_x_continuous(breaks = seq(min(deer_cam_data$start_time), max(deer_cam_data$start_time), by = 2)) +
scale_y_continuous(breaks = seq(min(deer_cam_data$cam_id), max(deer_cam_data$cam_id), by = 5)) +
custom.theme()
print(deer.cam.time.heatmap)